package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsGoodsMapper;
import com.qf.pojo.DtsGoods;
import com.qf.service.AdminGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/23 21:44
 */
@Service
public class AdminGoodsServiceImpl implements AdminGoodsService {

    @Autowired
    private DtsGoodsMapper dtsGoodsMapper;

    /**
     * 查看
     * @param goodsSn
     * @param name
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @return
     */
    @Override
    public IPage<DtsGoods> findListByQuery(String goodsSn, String name, Integer page, Integer limit, String sort, String order) {
        return dtsGoodsMapper.selectPage(new Page(page,limit)
            ,new QueryWrapper<DtsGoods>()
                        .like(!StringUtils.isEmpty(name),"name",name)
                        .eq(!StringUtils.isEmpty(goodsSn),"goods_sn",goodsSn)
                        .orderBy(!StringUtils.isEmpty(sort),"DESC".equalsIgnoreCase(order),sort)
            );
    }

    /**
     * 添加
     * @param dtsGoods
     * @return
     */
    @Override
    public DtsGoods create(DtsGoods dtsGoods) {
        dtsGoods.setGoodsSn(dtsGoods.getGoodsSn());
        dtsGoods.setName(dtsGoods.getName());
        dtsGoods.setBrowse(dtsGoods.getBrowse());
        dtsGoods.setSales(dtsGoods.getSales());
        dtsGoods.setApproveStatus(dtsGoods.getApproveStatus());
        dtsGoods.setBrokerageType(dtsGoods.getBrokerageType());
        dtsGoodsMapper.insert(dtsGoods);
        return dtsGoods;
    }

    @Override
    public DtsGoods update(DtsGoods dtsGoods) {
        dtsGoodsMapper.updateById(dtsGoods);
        return dtsGoods;
    }

    @Override
    public DtsGoods delete(DtsGoods dtsGoods) {
        dtsGoodsMapper.deleteById(dtsGoods);
        return dtsGoods;
    }
}
